home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12378 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.arch.embedded,comp.lang.c
  4. Subject: Re: Using malloc of C on embedded system?
  5. Date: 31 Mar 1996 12:48:30 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4jmr2uINN3cm@keats.ugrad.cs.ubc.ca>
  8. References: <4jml7h$cbc@castor.usc.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4jml7h$cbc@castor.usc.edu>,
  12. Stannon Yen <chuitiny@castor.usc.edu> wrote:
  13. >Hello,
  14. >
  15. >   This is just a general question. Is it possible to use C function
  16. >malloc and free on system that has no OS? How can I setup the memory
  17. >pool for dynamic allocation/deallocation of memory?
  18.  
  19. Here is where the ISO standard's distinction between a ``hosted'' and
  20. ``freestanding'' implementation comes in handy.
  21.  
  22. Presumably, the embedded development environment is freestanding, which means
  23. that you are allowed to define your own malloc() function with external
  24. linkage.
  25.  
  26. How you do this is entirely up to you. You may wish to do research into
  27. dynamic storage allocation methods. The Art of Computer Programming volumes by
  28. Knuth are a good starting point.
  29.  
  30. The implementation will depend a great deal on the overall architecture of the
  31. embedded system. For example, if it has a protected kernel that manages virtual
  32. address spaces, this will obviously have an impact over how you implement
  33. malloc. Your memory use might be divided between per-process memory
  34. _allocation_ scheme with your malloc() which draws on an underlying memory
  35. _management_ scheme implemented in the kernel.
  36.  
  37. Or, you could make malloc the only memory allocation function. The simplest
  38. case is the machine with some flat amount of RAM after the end of your OS. You
  39. take this and do heap allocation within it: the sample malloc() allocation
  40. given in K&R2 (the chapter covering UNIX system interfaces) might be something
  41. worth looking at.
  42. -- 
  43.  
  44.